home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 7
/
Aminet 7 - August 1995.iso
/
Aminet
/
comm
/
tcp
/
AmiTCPtnserv.lha
/
tnserv
/
fakesr
/
devinit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-01-15
|
6KB
|
172 lines
/* #define _USEOLDEXEC_ 1 */
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/memory.h>
#include <exec/resident.h>
#include <exec/libraries.h>
#include <exec/devices.h>
#include <libraries/dos.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <string.h>
#include <dos.h>
#include "fakesr.h"
#include "fakesrprivate.h"
typedef LONG (*PFL)(); /* pointer to function returning 32-bit int */
#define DEBUGBREAK() __emit(0x4afc)
struct Library *SysBase;
/* library initialization table, used for AUTOINIT libraries */
struct InitTable {
ULONG *it_DataSize; /* library data space size */
PFL *it_FuncTable; /* table of entry points */
APTR it_DataInit; /* table of data initializers */
PFL it_InitFunc; /* initialization function to run */
};
/* symbols generated by blink */
extern char __far _LibID[]; /* ID string */
extern char __far _LibName[]; /* Name string */
extern char __far RESLEN; /* size of init data */
extern long __far NEWDATAL; /* size of global data */
extern PFL _LibFuncTab[]; /* my function table */
#define DATAWORDS ((long)&NEWDATAL) /* magic to get right tpye of reloc */
#define SIZEJMPTAB ((long)libbase->fsd_origbase->fsd_numjmps)
/* size in bytes of jmp table */
#define MYREVISION 0 /* revision number */
/* From libent.o, needed to determine where data is loaded by loadseg */
extern long far _Libmergeddata;
struct InitTable __far _LibInitTab = {
(long *)(&RESLEN+sizeof(struct FakeSerDevice)),
_LibFuncTab,
NULL, /* will initialize my own data */
_LibInit,
};
__saveds __asm
ULONG _LibInit( register __a0 APTR seglist,
register __d0 struct FakeSerDevice *libbase )
{
long *reloc;
long *sdata;
char *ddata;
long nrelocs;
void *SysBase;
SysBase=*((void **)0x00000004);
libbase->fsd_SegList = (ULONG) seglist;
/* DEBUGBREAK();*/
/* init. library structure (since I don't do automatic data init.) */
libbase->fsd_Dev.dd_Library.lib_Node.ln_Type = NT_DEVICE;
libbase->fsd_Dev.dd_Library.lib_Node.ln_Name = _LibName;
libbase->fsd_Dev.dd_Library.lib_Flags = 0; /* LIBF_SUMUSED | LIBF_CHANGED;*/
libbase->fsd_Dev.dd_Library.lib_Version = 1;
libbase->fsd_Dev.dd_Library.lib_Revision = MYREVISION;
libbase->fsd_Dev.dd_Library.lib_IdString = (APTR) _LibID;
/* Start of copy of global data after structure */
ddata = (char *)libbase + sizeof(struct FakeSerDevice);
sdata = (long *)&_Libmergeddata; /* where loadseg loaded the data */
memcpy(ddata, (void *)sdata, DATAWORDS*4);
/* KPrintF("DATAWORDS=%ld\n",(long)DATAWORDS);*/
/* perform relocs if we want one global section for all programs */
/* that have this lib open. If we want a global section for each */
/* open, copy the relocs, and do them on each open call. */
sdata = sdata + DATAWORDS;
nrelocs = *sdata;
sdata++;
/* KPrintF("sdata=%lx\n",(long)sdata);
KPrintF("nrelocs=%ld\n",(long)nrelocs);
DEBUGBREAK();
while (nrelocs > 0)
{
reloc = (long *)((long)ddata + *sdata++);
*reloc += (long)ddata;
nrelocs--;
}*/
_UserLibInit(libbase);
/*DEBUGBREAK();*/
return ( (ULONG) libbase );
}
LONG __saveds __asm
_LibOpen( register __a6 struct FakeSerDevice *libbase, register __a1 void *IORequest, register __d0 LONG UnitNum, register __d1 ULONG Flags)
{
void *SysBase;
SysBase=*((void **)0x00000004);
/* DEBUGBREAK(); */
/* mark us as having another customer */
libbase->fsd_Dev.dd_Library.lib_OpenCnt++;
/* clear delayed expunges (standard procedure) */
libbase->fsd_Dev.dd_Library.lib_Flags &= ~LIBF_DELEXP;
((struct IORequest *)IORequest)->io_Error=0;
_UserLibOpen(libbase,IORequest,UnitNum,Flags);
if (((struct IORequest *)IORequest)->io_Error) {
/* Error */
libbase->fsd_Dev.dd_Library.lib_OpenCnt--;
}
/* DEBUGBREAK();*/
return ( (LONG) libbase );
}
ULONG __saveds __asm
_LibClose( register __a6 struct FakeSerDevice *libbase,register __a1 void *IORequest)
{
ULONG retval = 0;
void *SysBase;
SysBase=*((void **)0x00000004);
_UserLibClose(libbase,IORequest);
if (( --libbase->fsd_Dev.dd_Library.lib_OpenCnt == 0 ) &&
( libbase->fsd_Dev.dd_Library.lib_Flags & LIBF_DELEXP ))
{
/* no more people have me open,
* and I have a delayed expunge pending
*/
retval = _LibExpunge( libbase ); /* return segment list */
}
return (retval);
}
ULONG __saveds __asm
_LibExpunge( register __a6 struct FakeSerDevice *libbase )
{
ULONG seglist = 0;
LONG libsize;
void *SysBase;
SysBase=*((void **)0x00000004);
libbase->fsd_Dev.dd_Library.lib_Flags |= LIBF_DELEXP;
if ( libbase->fsd_Dev.dd_Library.lib_OpenCnt == 0 )
{
/* really expunge: remove libbase and freemem */
_UserLibCleanup(libbase);
seglist = libbase->fsd_SegList;
Remove( (struct Node *) libbase);
libsize = libbase->fsd_Dev.dd_Library.lib_NegSize + libbase->fsd_Dev.dd_Library.lib_PosSize;
FreeMem( (char *) libbase - libbase->fsd_Dev.dd_Library.lib_NegSize,(LONG) libsize );
}
/* return NULL or real seglist */
return ( (ULONG) seglist );
}